package yang.learn.service.impl;

import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import yang.learn.dao.UserDao;
import yang.learn.entity.User;
import yang.learn.service.UserService;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

//    @Autowired(required = false)
    @Resource(name = "userDao",type = UserDao.class)
    private UserDao userDao;

    @Override
    public void add(User user) {
        userDao.add(user);
    }

    @Override
    public void del(User user) {
        userDao.del(user);
    }

    @Override
    /**
     * 如果用户不为空，即存在
     * 且修改的用户账号与数据库中的账号一致
     */
    public void change(User user, String new_password, String true_password) {
        if (user.getUser_password() != null && new_password.equals(true_password))
            user.setUser_password(new_password);
        userDao.change(user);
    }

    public List<User> queryAll(){
        List<User> list = userDao.queryAll();
        return list;
    }

    @Override
    public User queryId(User user) {
        User databaseUser = userDao.queryId(user);
        return databaseUser;
    }

    @Override
    public User queryAccount(User user) {
        User databaseUser = userDao.queryAccount(user);
        return databaseUser;
    }

    /**
     * 账户登录
     */
    public void login(){

    }

}
